package mymqsender.conf;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * create by caoqg on 2021/8/4
 * 功能说明:
 */
@Configuration
//@ConfigurationProperties(prefix = "spring.rabbitmq")
public class RabbitConConfig {
    //@Primary
//    @Bean(name = "connectionFactory")
    @Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
        connectionFactory.setAddresses("rabbitmq.caoqg.cn");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("zrtest");
        connectionFactory.setPassword("123456");
        connectionFactory.setVirtualHost("/zrtest");
        //   connectionFactory.setVirtualHost(mqRabbitVirtualHost);
        //   connectionFactory.setPublisherConfirms(true);
        //该方法配置多个host，在当前连接host down掉的时候会自动去重连后面的host


        return connectionFactory;
    }
}


